studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
37 lines (36 loc) • 908 B
JavaScript
import {
AllResponse,
createEffectAPIRoutes,
createJsonResponse,
Effect,
genLogger,
OptionsResponse
} from "../../../../effect.js";
import { OAuthAPIEffect } from "./_effects/index.js";
const { GET, OPTIONS, ALL } = createEffectAPIRoutes(
{
GET: (ctx) => genLogger("studiocms/routes/api/auth/[provider]/callback.GET")(function* () {
const { initCallback } = yield* OAuthAPIEffect;
return yield* initCallback(ctx);
}).pipe(OAuthAPIEffect.Provide),
OPTIONS: () => Effect.try(() => OptionsResponse({ allowedMethods: ["GET"] })),
ALL: () => Effect.try(() => AllResponse())
},
{
cors: { methods: ["GET", "OPTIONS"] },
onError: (error) => {
console.error("API Error:", error);
return createJsonResponse(
{ error: "Internal Server Error" },
{
status: 500
}
);
}
}
);
export {
ALL,
GET,
OPTIONS
};